-- @owner: wan005
-- @date: 2024-08-12
-- @testpoint: right()函数作为对象名的测试，部分测试点合理报错

--prestep1:切换B库;expect:执行成功
@conn PrimaryDbBmode;
show sql_compatibility;

--step1:作为列名;expect:报错
drop table if exists right_test cascade;
create table right_test(right text);
insert into right_test values('0');

--step2:作为索引名;expect:报错
create index on right_test(right);

--step3:作为表名;expect:报错
drop table if exists right cascade;
create table right(right text);

--step4:作为数据库名;expect:报错
drop database if exists right;
create database right;
drop database right;

--step5:作为外部数据源名;expect:报错
drop data source if exists right;
create data source right;
drop data source right;

--step6:作为自定义函数名;expect:成功
create or replace function right(c1 text)
returns text
as  $$
begin
    return c1;
end;
$$language plpgsql;
/
drop function if exists right(text);

--step7:作为存储过程名;expect:成功
drop table if exists t_right_0019;
create table t_right_0019(c1 text);
CREATE OR REPLACE PROCEDURE right(P1 IN text) AS
BEGIN
insert into t_right_0019 values ('00001');
raise info '测试right作为存储过程名';
END;
/
drop procedure if exists right(text);

--step8:作为角色名;expect:报错
drop role if exists right;
create role right with password 'gauss@123' valid until '2001-12-12';
drop role right;

--step9:作为用户组名;expect:报错
drop group if exists right;
create group right with password 'gauss@123';
drop group right;

--step10:作为模式名;expect:报错
drop schema if exists right;
create schema right;
drop schema right;

--step11:作为序列名;expect:成功
create sequence public.right start 100 cache 50;
drop sequence public.right;

--step12:作为用户名;expect:报错
drop user if exists right;
CREATE USER right PASSWORD 'Bigdata@123';
drop user right;

--step14:作为游标名;expect:报错
drop table if exists right_test cascade;
create table right_test(cid int,fid int);
start transaction;
cursor right for select * from right_test order by 1;
close right;
end;

--step15:清理环境;expect:成功
drop table if exists right_test cascade;
drop table if exists right cascade;
drop table if exists t_right_0019;